package org.example.demo1;

public class demo1 {
    public static void main(String[] args) {
        tickets tickets = new tickets();
        new Thread(()->{
            for (int i = 0; i < 50; i++) {
              tickets.sell();
            }
        },"我").start();
        new Thread(()->{
            for (int i = 0; i < 50; i++) {
                tickets.sell();
            }
        },"你").start();
        new Thread(()->{
            for (int i = 0; i < 50; i++) {
                tickets.sell();
            }
        },"它").start();

    }
}
class tickets{
    private int ticketNums = 50;

   public synchronized void sell(){
       if (ticketNums > 0){
           System.out.println(Thread.currentThread().getName()+"卖出了第"+ticketNums--+"张票,剩余"+ticketNums+"张票");
       }
    }
}
